import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_CAPACITY = 10;

    public MyStack(){
        this.elem = new int[DEFAULT_CAPACITY];
    }

    public void push(int val){
        if(isFull()){
            this.elem = Arrays.copyOf(this.elem, this.elem.length * 2);
        }
        this.elem[usedSize++] = val;
    }

    private boolean isFull(){
        return this.usedSize == this.elem.length;
    }

    public int pop(){
        if(isEmpty()) {
            throw new RuntimeException("栈为空");
        }
        this.usedSize--;
        return this.elem[usedSize];
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }

    public int peek(){
        return this.elem[usedSize - 1];
    }

    public int size(){
        return this.usedSize;
    }
}
